<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .folder {
      cursor: pointer;
    }
    .folder:before {
      content: '+';
    }
    .folder > .folder-inner {
      display: none;
      margin-left: 20px;
    }
    .folder.is-open > .folder-inner {
      display: block;
    }
    .folder.is-open:before {
      content: '-';
    }
    .file:before {
      content: '*';
    }
  </style>
</head>
<body>
  <p>文件夹树形结构(组合模式)</p>
  <div class="file-tree">
    <!-- <div class="folder">
      <span class="folder-title">父文件夹</span>
      <div class="folder-inner">
          <div class="file">文件1</div>
          <div class="folder">
              <span class="folder-title">子文件夹</span>
              <div class="folder-inner">
                <div class="file">文件2</div>
              </div>
          </div>
      </div>
    </div> -->
  </div>
  <script src="dist/composite/index.js"></script>
  <script>
    const Folder = Thanos.default;
    var mockData = {
        id: '1',
        files: [
          {
            id: '1_1',
            files: [
              { id: '1_1_1',
                files: [
                  { id: '1_1_1_1' }
                ]
              },
              { id: '1_1_2' },
              { id: '1_1_3' }
            ]
          },
          {
            id: '1_1',
            files: [
              { id: '1_1_1',
                files: [
                  { id: '1_1_1_1' }
                ]
              },
              { id: '1_1_2' },
              { id: '1_1_3' }
            ]
          },
          {
            id: '1-2'
          }
        ]
      };
    var oTree = document.querySelector('.file-tree');

    createFolder(oTree, mockData);
    // 创建文件夹
    function createFolder(dom, data) {
      if (data.id) {
        var oDom = document.createElement('div');
        oDom.classList.add('folder')
        oDom.innerHTML = `
          <span class="folder-title">文件夹${data.id}</span>
          <div class="folder-inner"></div>
        `;
        var folder = new Folder({
          id: data.id,
          dom: oDom,
          files: data.files
        });
        oDom.folder = folder;
        dom.appendChild(oDom)
      }
    }
  </script>
</body>
</html>